const station2 = document.querySelector('#station2');
const identity2 = document.querySelector('#identity2');
const station2Error = document.querySelector('#station2-errorMessage');
const identity2Error = document.querySelector('#identity2-errorMessage');

(function () {
  const forget = document.querySelector('#forget');
  const Return = document.querySelector('#return');
  const fcontainer = document.querySelector(".forget-container");
  const Lcontainer = document.querySelector(".login-container");
  forget.addEventListener('click', () => {
    fcontainer.classList.remove('turnRight');
    fcontainer.classList.add('turnLeft');
    Lcontainer.classList.add('turnLeft');
    station2.focus();
    station2Error.classList.remove('block')
  }
  );
  Return.addEventListener('click', () => {
    Lcontainer.classList.remove('turnLeft');
    Lcontainer.classList.add('turnRight');
    fcontainer.classList.add('turnRight');
    station1.focus();
    station1Error.classList.remove('block');
  }
  );
})();

station2.addEventListener('click', () => {
  station2Error.classList.remove('block')
});
identity2.addEventListener('click', () => {
  identity2Error.classList.remove('block')
  document.querySelector('.select-options2').classList.add('block')
});
identity2.addEventListener('blur', () => {
  identity2Error.classList.remove('block')
  document.querySelector('.select-options2').classList.remove('block')
});

(function () {
  const submit = document.querySelector('#submit');
  submit.addEventListener('click', () => {
    const identity2Value = identity2.value;
    const station2Value = station2.value;
    let flag = true;
    station2Error.classList.remove('block');
    identity2Error.classList.remove('block');
    if (station2Value.trim() === '') {
      station2Error.classList.add('block');
      station2Error.innerHTML = '工号信息不能为空';
      flag = false;
    }
    else if (!numberRegex1.test(station2Value)) {
      station2Error.classList.add('block');
      station2Error.innerHTML = '工号信息格式错误';
      flag = false;
    }
    if (identity2Value.trim() === '') {
      identity2Error.classList.add('block');
      identity2Error.innerHTML = '身份信息不能为空';
      flag = false;
    }
    else if (!letterRegex.test(identity2Value)) {
      identity2Error.classList.add('block');
      identity2Error.innerHTML = '身份信息格式错误';
      flag = false;
    }
    if (!flag) {
      console.log('提交失败');
    }
    else {
      const forgetData = {
        station: station2Value,
        identity: identity2Value
      };
      const url = "/admin/forget";
      axios.post(url, forgetData).then(function (res) {
        if (res.data.code == 1) {
          alert(res.data.data);
          console.log('提交成功');
          inputElements.forEach(element => {
            element.value = '';
            station2Error.classList.remove('block');
            identity2Error.classList.remove('block');
            element.style.backgroundColor = 'rgba(35,39,46,0.5)';
          });
        }
        else {
          alert(res.data.msg);
          console.log('信息错误');
        }
      });
    }
  });

})();

function selectOption2(option) {
  identity2.value = option;
  identity2.style.backgroundColor = 'rgba(22, 31, 32)';
  identity2.style.boxShadow = '0 4px 9px #161818';
};

